/*
 * @Author: 0x9DEFA478
 * @Date: 2025-07-26 20:19:24
 * @LastEditTime: 2025-07-27 15:37:23
 * @LastEditors: 0x9DEFA478
 * @Description: 
 * 
 */
#ifndef hAtomic_H_Atomic_Concurrency_HPP_
#define hAtomic_H_Atomic_Concurrency_HPP_
#include "./H_Atomic_Empty.hpp"
#include "H_Concurrency.hpp"




namespace H{

  namespace Atomic{

    template<typename ValueType>
    class Count_Concurrency{
      public:
        using Type=ValueType;
      public:
        Count_Concurrency(ValueType value):value(value){}
        ~Count_Concurrency(){}

        ValueType load(){return value;}
        void store(ValueType value){this->value=value;}
        ValueType increment(ValueType value){
          ValueType r;
          lock.lock();
          r=this->value;
          r+=value;
          this->value=r;
          lock.unlock();
          return r;
        }
        ValueType decrement(ValueType value){
          ValueType r;
          lock.lock();
          r=this->value;
          r-=value;
          this->value=r;
          lock.unlock();
          return r;
        }
      private:
        ValueType value;
        Lock lock;
    };

  }

}




#endif //hAtomic_H_Atomic_Concurrency_HPP_
